package com.road.yishi;

import com.road.common.core.ServerType;
import com.road.yishi.base.Constants;
import com.road.yishi.core.CastleConfig;
import com.road.yishi.core.CastleServerHandler;

/**
 * @Description :
 * @FileName: CastleServer.java
 * @Author :WeiHui.Zhang
 * @Data : 2016年2月19日 下午8:44:06
 * @Version:V1.00
 */
public final class CastleServer extends BaseServer<CastleConfig> {

	private static CastleServer castleServer;

	private static CastleConfig castleConfig;
	
	public static CastleServer getInstance() {
		return Singleton.instance;
	}

	private final static class Singleton {

		private static CastleServer instance = new CastleServer();
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();

		castleServer = CastleServer.getInstance();
		castleConfig = castleServer.getConfig();

		System.out.println(castleConfig.crossPath());
		System.out.println(castleConfig.globalPath());
		System.out.println(castleConfig.serverId());

		if (!castleServer.start()) {
			System.err.println("CastleServer启动失败!");
			System.exit(1);
			return;
		}

		LOGGER.info("CastleServer启动成功! 启动耗时: {} ms。 " , (System.currentTimeMillis() - time));
	}

	@Override
	public boolean start() {
		if (!super.start()) {
			return false;
		}

		if (!initComponent(initMina(new CastleServerHandler(), ServerType.CASTLE), "逻辑服Socket服务")) {
			return false;
		}

		return true;
	}

	@Override
	protected String getGlobalFilePath() {
		return castleConfig.globalPath();
	}

	@Override
	protected String getCrossFilePath() {
		return castleConfig.crossPath();
	}

	@Override
	protected int getServerId() {
		return castleConfig.serverId();
	}

	@Override
	protected String getScanPackage() {
		return Constants.castleAdminScanPackage;
	}
}
